home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / libc / Net_NetToHostShort.c < prev    next >
C/C++ Source or Header  |  1989-01-27  |  1KB  |  60 lines

  1. /* 
  2.  * Net_NetToHostShort.c --
  3.  *
  4.  *    Convert a short integer from network to host byte ordering.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/lib/net/RCS/Net_NetToHostShort.c,v 1.3 89/01/27 16:38:40 mendel Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21.  
  22. #include "machparam.h"
  23.  
  24. /* 
  25.  *----------------------------------------------------------------------
  26.  *
  27.  * Net_NetToHostShort --
  28.  *
  29.  *    Convert a short integer in network byte order to an short integer in 
  30.  *    host byte order.
  31.  *
  32.  * Results:
  33.  *    The short integer in host byte order.
  34.  *
  35.  * Side effects:
  36.  *    None.
  37.  *
  38.  *----------------------------------------------------------------------
  39.  */
  40. unsigned short 
  41. Net_NetToHostShort(shortInt)
  42.     unsigned short shortInt;     /* A short int in network byte order. */
  43. {
  44.  
  45. #if BYTE_ORDER == LITTLE_ENDIAN
  46.     union swab {
  47.         unsigned short s;
  48.         unsigned char  c[2];
  49.     } in, out;
  50.  
  51.     in.s = shortInt;
  52.     out.c[0] = in.c[1];
  53.     out.c[1] = in.c[0];
  54.  
  55.      return (out.s);
  56. #else
  57.     return (shortInt);
  58. #endif
  59. }
  60.